< previous page page_194 next page >

Page 194
Table 9.3 ASCII Codes for Some Commonly Used Characters
CodeRepresents
8Backspace
9Tab
10Line feed
13Carriage return
32Space
34Double quotation mark (")
480 (the character for zero)
65A
97a

Asc is the companion function to the Chr function. Asc returns the ASCII code of the input character. The following code shows how Asc is used:
Print Asc("A") 'Returns 65
Strings and Numbers
A string value can actually contain numeric digits, as you can see here:
Dim sStringVal As String
Dim nNumber As Integer
nNumber = 99 'A number that can be used with math expressions
sStringVal = "16 candles" 'A string that cannot be used with math expressions
You may already know that some numbers are often treated as character strings. Zip codes and phone numbers are two such examples. However, sometimes you need to convert a number to a string variable to use it in a string function or to print it in combination with another string. Likewise, you sometimes need to use numbers contained in a string variable in a mathematical equation or a numeric function.
Visual Basic provides the Str function to convert a number to a string and the Val function to convert a string to a number. To convert a number to a string, you can do the following:
numstr = Str(inptnum)
numstr represents a string variable that contains the output of the function. inptnum represents the number to be converted. It can be a number, a numeric variable, or a numeric function. If inptnum is a positive number, Str returns a space in front of the number because Str reserves one character to contain a negative sign, if necessary.
To convert a string to a number, you can use the Val function, as follows:
numvar = Val(inptstr)

 
< previous page page_194 next page >